import { Component, OnInit } from '@angular/core';
import { registerUserModel } from '../domain/user';
import { UserService } from '../service/user.service'
import { Router } from '@angular/router';
@Component({
  selector: 'app-register',
  templateUrl: './register.component.html',
  styleUrls: ['./register.component.css']
})
export class RegisterComponent implements OnInit {

  registerUserModel: registerUserModel;

  constructor(private userService: UserService, private _router: Router) { }

  register(name: string, username: string, password: string, position: string, department: string) {
    if(department == "请选择...") {
      department = "/";
    }
    this.registerUserModel = new registerUserModel(username, password, name, department, position);
    this.userService.registerUser(this.registerUserModel).then( () => {
      alert("😄 注册成功！")
      this._router.navigateByUrl('log-in-interface')
    }
    )
  }

  showTxtb(myPosition: string){
    var txt_b = document.getElementById('department');
    //1员工  2部门经理  3副总经理  4总经理
    if(myPosition == '员工' || myPosition == '部门经理'){
      txt_b.style.visibility='visible';
    }else{
      txt_b.style.visibility='hidden';
    }
      
  }

  ngOnInit() {
    
  }

}
